package com.gsit.ocraspect.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.gsit.ocrbatch.domain.Login;

@Component("authenticationInterceptor")
public class AuthenticationInterceptor extends HandlerInterceptorAdapter{
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String uri = request.getRequestURI();
		System.out.println("The URL is "+uri);
		if (!uri.endsWith("login") && !uri.endsWith("OcrAspectWeb/")) {
			Login login = (Login) request.getSession().getAttribute("login");
			if (login == null) {
				response.sendRedirect("/");
				return false;
			}
		}
		return true;
	}

}
